defmodule Giom.Accounting.Ist do
  use Ecto.Schema
  import Ecto.Changeset

  # Interim stock transaction table
  schema "ists" do
    field :ist_id, :string
    field :stock_code, :string
    field :price, :decimal
    field :qty, :decimal
    field :i_qty, :decimal,default: 0.0
    field :i_qty2, :decimal,default: 0.0
    field :i_qty3, :decimal,default: 0.0
    field :stock_name, :string
    field :amount, :decimal, virtual: true
   
    timestamps()
  end

  @doc false
  def changeset(ist, attrs) do
    ist
    |> cast(attrs, [:ist_id, :stock_name, :qty, :price, :stock_code, :i_qty, :i_qty2, :i_qty3])
    |> validate_required([:ist_id, :stock_name, :qty, :price, :stock_code])
    |> foreign_key_constraint(:stock_code)
  end
end
